﻿jQuery(document).ready(function () {
    jQuery('#LoadingImage').dialog({
        title: 'Uploading!',
        width: 235,
        height: 237,
        closed: true,
        cache: false,
        modal: true,

    });
    getSellOutUploadHistory();
    getStockUploadHistory();
    jQuery('#ajaxUploadSellOut')
        .ajaxForm({
            beforeSubmit: showLoading,
            url: '/api/Upload/PostUploadSellOut/', // or whatever
            dataType: 'json',
            success: function (response) {
                //getSellOut();
                getSellOutUploadHistory();
                stopLoading();
                alert(response);
            },
            error: function () {
                stopLoading();
                alert("can't upload file please check file size we allow max file is 50M");
            }
        });

    jQuery('#ajaxUploadDataStock')
        .ajaxForm({
            beforeSubmit: showLoading,
            url: '/api/Upload/PostDataStockBalance/', // or whatever
            dataType: 'json',
            success: function (response) {
                //getStock();
                getStockUploadHistory();
                stopLoading();
                alert(response);
            },
            error: function () {
                stopLoading();
                alert("can't upload file please check file size we allow max file is 50M");
            }
        });

    function showLoading() {
        jQuery('#LoadingImage').dialog('open');
    }

    function stopLoading() {
        jQuery('#LoadingImage').dialog('close');
    }
});

function getSellOut() {
    jQuery('#selloutImport').datagrid({
        url: "/api/ProductApi/PostUploadSellOut",
        onLoadSuccess: function (data) {
            //set default to tab wait for approve
        }
    });
}

function getSellOutUploadHistory() {
    jQuery('#selloutImportHistory').datagrid({
        url: "/api/ProductApi/PostHistorySellOutUpload",
        onLoadSuccess: function (data) {
            //set default to tab wait for approve
        }
    });
    //jQuery.ajax({
    //    type: "POST",
    //    url: "/api/ProductApi/PostHistorySellOutUpload",
    //    async: true,
    //    dataType: "json",
    //    success: function (data) {

    //    },
    //    error: function (data) {

    //    }
    //});

}

function getStockUploadHistory() {
    jQuery('#stockbalanceImportHistory').datagrid({
        url: "/api/ProductApi/PostHistoryStockUpload",
        onLoadSuccess: function (data) {
            //set default to tab wait for approve
        }
    });
    //jQuery.ajax({
    //    type: "POST",
    //    url: "/api/ProductApi/PostHistoryStockUpload",
    //    async: true,
    //    dataType: "json",
    //    success: function (data) {

    //    },
    //    error: function (data) {

    //    }
    //});

}

function getStock() {

    jQuery('#stockbalanceImport').datagrid({
        url: "api/ProductApi/PostUploadStockBalance",

        onLoadSuccess: function (data) {
            //set default to tab wait for approve
            //jQuery('#documentTab').tabs('select', 1)
            //var orderWaitForApprove = jQuery.grep(jQuery('#orderAllList').datagrid('getRows'), function (d, i) {
            //    return d.Status == 2
            //});
            //jQuery('#orderWaitForApproveList').datagrid({
            //    data: orderWaitForApprove,
            //    loadFilter: pagerFilter,
            //    onDblClickRow: function (index, fields, value) {
            //        OpenOrderDetailsPopup(fields.OrderNo, fields.Status);
            //    }
            //});
        }
    });
}